﻿<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>我的购物车</title>
<link href="__PUBLIC__/home/css/style.css" type="text/css" rel="stylesheet" />
<script src="__PUBLIC__/home/js/jquery-1.7.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/home/js/common.js"  type="text/javascript"></script>

</head>
<body class="index">
<!-- header -->
<div class="w1200">
	<div class="position"><a href="#">首页</a> > <a href="#">购物车</a></div>
    
    <div class="shopcar">
    	<div class="shop_lc"><span class="sp01">我的购物车</span><span class="sp02">填写提交信息表单</span><span class="sp03">在线支付</span></div>
      	<dl>
        	<dt><span>我的购物车</span></dt>
            <dd>
            	<table width="100%" cellpadding="0" cellspacing="0" border="0">
                  <tr class="tr_t">
                    <td width="4%"><input type="checkbox" checked="checked" class="allcheck" /></td>
                    <td width="4%">全选</td>
                    <td width="33%">商品</td>
                    <td width="23%">单价</td>
                    <td width="11%">数量</td>
                    <td width="14%">小计</td>
                    <td width="11%">操作</td>
                  </tr>
        <form action="{$addressinfo}" method="post">
                <div class="shopreturn">
                    <php>$a=0;foreach($shopCar as $key => $value){</php>
                        <tr class="tr_c">
                          <td><input type="checkbox" checked="checked" class="onecheck" name="shop[]" value="<?php echo $value['id']; ?>"  status='1'/><input type="hidden" name="id_num[]" value="<?php echo $value['id'].'*'.$value['com_num']; ?>"></td>
                          <td colspan="2">
                              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td width="15%"><img src="__PUBLIC__/upload/<?php echo $value['com_img_name']; ?>"/></td>
                                  <td width="85%"><a href="#" class="title"><?php echo $value['com_name'].'　'.$value['com_discription'];?></a></td>
                                </tr>
                              </table>
                          </td>
                          <td class="price">￥<span><?php echo $value['com_price']; ?></span></td>
                          <td><span class="jian" id="jian">-</span><input type="hidden" name="store" class="store" id="store" value="<?php echo $value['com_store']; ?>" /><input type="text" value="<?php echo $value['com_num']; ?>" id="num" name="num[]" class="num" style="width: 65px;"/><span class="jia" id="jia">+</span></td>
                          <td>￥<span class="oneprice"><?php echo $value['com_price']*$value['com_num']; ?></span></td>
                          <td><a href="/Home/Shopcar/delete?shopid=<?php echo $value['id']; ?>"  class="del">删除</a></td>
                        </tr>
                      <php>$a+=$value['com_price']*$value['com_num'];}</php>
                </div>
       
                  <tr class="tr_d">
                    <td colspan="7">
                    	<table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td width="75%"><span class="del"><a href="#">删除选中商品</a></span></td>
                            <td width="11%">已选商品 <!--  <strong>1</strong>  件 --></td>
                            <td width="14%" class="all_price">合计：<font>￥<strong><?php echo $a; ?></strong></font></td>
                          </tr>
                        </table>
                    </td>
                  </tr>
                </table>
                <div class="clear"></div>
                
       		  </dd>
            </dl>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="go_tb">
             <tr>
               <td width="20%"><a href="{$product}" class="go_buy">继续购物</a></td>
               <td width="63%">&nbsp;</td>
               <td width="17%" align="right"><button><a class="code">结 算</a></button></td>
             </tr>
            </table>
        </form>
        <div class="clear"></div>
    </div>
</div>

<!--footer-->
<!-- 购物车的选框与总价格联动 -->
<script type="text/javascript">
$('.onecheck').on('click',function(){
    var status=parseInt($(this).attr('status'),0,'intval');
    
    var money=parseInt($(this).parent().parent().find('td .oneprice').text(),0,'intval');
    if (status===1) {
      $(this).parent().parent().find('td .onecheck').attr('status',"0");
      var all=parseInt($('.all_price').find('font strong').text())-money;
    }else{  
      $(this).parent().parent().find('td .onecheck').attr('status',"1");
      var all=parseInt($('.all_price').find('font strong').text())+money;
    }
    $('.all_price').find('font strong').text(all);
});
</script>
<!-- 购物车删除商品 -->
<script type="text/javascript">
    $(function(){
        $('.del').on('click',function(){
            $(this).parent().parent().remove();
            $.get($(this).attr('href'),function(){});
            return false;
        });
    });
</script> 
<!-- 循环出购物车中前面的选框 -->
<script type="text/javascript">
  $(function(){
      if ($('.allcheck').attr('checked') & $('.onecheck').attr('checked')) {
           $('.allcheck').on('click',function(){
              $('.allcheck').attr('checked','#');
              
          });
          $('.onecheck').on('click',function(){
              $(this).attr('checked','#');
              $('.allcheck').attr('checked','#');
          });
      }else{
        $('.allcheck').on('click',function(){
            $('.allcheck').attr('checked','checked');
            $('.onecheck').attr('checked','checked');
        });
      }
  });
</script>
<script type="text/javascript">
    $('.jian').on('click',function(){
         var jian=parseInt($(this).parent().find('.num').attr('value'));
         if (jian > 1) {
           $(this).parent().find('.num').attr('value',jian-1); 
           var oneprice=parseInt($(this).parent().prev('.price').find('span').text(),0,'intval');//获取商品的单价
           var onenum=parseInt($(this).parent().find('.num').attr('value'));//获取商品变动的数量
           var onesum=oneprice*onenum;//算出每个商品各自的价格
           $(this).parent().next().find('span').text(onesum);//商品小计赋值
           //总价的变动
           var all=parseInt($('.all_price strong').text(),0,'intval');
           all=all-oneprice;
           $('.all_price strong').text(all);
        }else{
            alert('已经是 1 了，不能再减了！');
        }
    });
    $('.jia').on('click',function(){
        var jia=parseInt($(this).prev('.num').attr('value'));
        var store=parseInt($(this).prev('.num').prev('.store').val());
        if (jia < store) {
           $(this).prev('.num').attr('value',jia+1);
           var oneprice=parseInt($(this).parent().prev('.price').find('span').text(),0,'intval');//获取商品的单价
           var onenum=parseInt($(this).prev('.num').attr('value'));//获取商品变动的数量
           var onesum=oneprice*onenum;//算出每个商品各自的价格
           $(this).parent().next().find('span').text(onesum);//商品小计赋值
           //总价的变动
           var all=parseInt($('.all_price strong').text(),0,'intval');
           all=all+oneprice;
           $('.all_price strong').text(all);
        }else{
            alert('库存不足！');
        }
    });
</script> 
</body>
</html>
